let checkCount = 1
let lastHour = 0;
let runFlag = false
let times = ['10:08', "18:08", "11:11"]
let gethHourObj = function () {
    let hourObj = {}
    times.map(x => {
        let split = x.split(":")
        let hour = Number(split[0])
        let minute = Number(split[1])
        let array = hourObj[hour]
        if (!array) {
            array = []
            hourObj[hour] = array
        }
        array.push(minute)
    })
    return hourObj;
}

let checkFun = function () {
    let now = new Date()
    let hourObj = gethHourObj()
    checkCount++;
    let nowHour = now.getHours()
    let nowMinute = now.getMinutes()
    if (lastHour != nowHour) {
        checkCount = 1
        lastHour = nowHour
    }
    console.log(` ${lastHour} 次数${checkCount} ${times} `)
    // 小时对了
    if (Object.keys(hourObj).filter(x => Number(x) == nowHour).length == 0) {
        return false
    }
    if (hourObj[nowHour].filter(x => { return x == nowMinute}).length == 0) {
        return false
    }
    return true
}

// 改变定时
changeInterval = function () {
    interval = setInterval(function () {
        if (checkFun()) {
            if (!runFlag){
                console.log("自动触发抢购中")
                let that = document.getElementById("pro-operation")
                    .getElementsByTagName("span")[0]
                rush.business.clickBtnRushBuy2(that)
                console.log("排队中请等待")
            }
            runFlag = true
        } else {
            runFlag = false
        }
    }, 0)
}

// 开始啦
changeInterval()


